package com.zf.apartment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zf.common.config.RuoYiConfig;
import com.zf.common.core.domain.model.LoginUser;
import com.zf.common.utils.ServletUtils;
import com.zf.common.utils.file.FileUploadUtils;
import com.zf.common.utils.file.MimeTypeUtils;
import com.zf.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zf.common.annotation.Log;
import com.zf.common.core.controller.BaseController;
import com.zf.common.core.domain.AjaxResult;
import com.zf.common.enums.BusinessType;
import com.zf.apartment.domain.Image;
import com.zf.apartment.service.IImageService;
import com.zf.common.utils.poi.ExcelUtil;
import com.zf.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 图片Controller
 * 
 * @author rxf
 * @date 2024-10-05
 */
@RestController
@RequestMapping("/apartment/image")
public class ImageController extends BaseController
{
    @Autowired
    private IImageService imageService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询图片列表
     */
    @PreAuthorize("@ss.hasPermi('apartment:image:list')")
    @GetMapping("/list")
    public TableDataInfo list(Image image)
    {
        startPage();
        List<Image> list = imageService.selectImageList(image);
        return getDataTable(list);
    }

    /**
     * 导出图片列表
     */
    @PreAuthorize("@ss.hasPermi('apartment:image:export')")
    @Log(title = "图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Image image)
    {
        List<Image> list = imageService.selectImageList(image);
        ExcelUtil<Image> util = new ExcelUtil<Image>(Image.class);
        util.exportExcel(response, list, "图片数据");
    }

    /**
     * 获取图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('apartment:image:query')")
    @GetMapping(value = "/{imageId}")
    public AjaxResult getInfo(@PathVariable("imageId") Long imageId)
    {
        return success(imageService.selectImageByImageId(imageId));
    }

    /**
     * 新增图片
     */
    @PreAuthorize("@ss.hasPermi('apartment:image:add')")
    @Log(title = "图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Image image)
    {
        return toAjax(imageService.insertImage(image));
    }

    /**
     * 修改图片
     */
    @PreAuthorize("@ss.hasPermi('apartment:image:edit')")
    @Log(title = "图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Image image)
    {
        return toAjax(imageService.updateImage(image));
    }

    /**
     * 删除图片
     */
    @PreAuthorize("@ss.hasPermi('apartment:image:remove')")
    @Log(title = "图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{imageIds}")
    public AjaxResult remove(@PathVariable Long[] imageIds)
    {
        return toAjax(imageService.deleteImageByImageIds(imageIds));
    }
}
